import re

def remove_non_chinese(text):
    '''去除文本中的所有非汉字字符'''
    return re.sub(r'[^\u4e00-\u9fff]+', '', text)

def remove_non_english_chars(text):
    # 正则表达式匹配任何非英文字母的字符并替换为空字符
    cleaned_text = re.sub(r'[^a-zA-Z]', '', text)
    return cleaned_text.lower()


def common_chars(str1, str2):
    common = []
    for char in str1:
        if char in str2 and char not in common:
            common.append(char)
    return common


def get_check_index(origin_str,target_str):
    check_index = len(target_str) -1
    if origin_str[check_index] == target_str[check_index]:
        return check_index
    elif origin_str[check_index - 1] == target_str[check_index -1]:
        return check_index
    elif origin_str[check_index - 2] == target_str[check_index -2]:
        return check_index
    elif (check_index +1 < len(origin_str)) and origin_str[check_index +1] == target_str[check_index]:
        return check_index +1
    elif origin_str[check_index -1] == target_str[check_index]:
        return check_index -1
    elif (check_index +2 < len(origin_str)) and origin_str[check_index +2] == target_str[check_index]:
        return check_index +2
    elif origin_str[check_index -2] == target_str[check_index]:
        return check_index -2
    else:
        check_index = len(target_str) - 2
        if origin_str[check_index] == target_str[check_index]:
            return check_index+1


